/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.base.controller;

import java.util.Map;
import java.util.List;
import com.dian.common.annotation.SysLog;
import com.dian.modules.base.entity.DistEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.dian.common.controller.AbstractController;
import com.dian.modules.base.service.DistService;
import com.dian.modules.base.vo.DistExportVO;
import com.dian.common.utils.PageUtils;
import com.dian.common.utils.R;


/**
 * 业务数据字典
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-06-26 17:50:12
 */
@RestController
@Api("业务数据字典接口")
@RequestMapping("base/dist")
public class DistController extends AbstractController{
    @Autowired
    private DistService distService;



    /**
     * 业务数据字典列表
     */
    @SysLog("业务数据字典列表")
    @GetMapping("/list")
    @ApiOperation("业务数据字典列表")
    @RequiresPermissions("base:dist:list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = distService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 业务数据字典信息
     */
    @SysLog("业务数据字典信息")
    @ApiOperation("业务数据字典信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("base:dist:info")
    public R info(@PathVariable("id") Long id){

        DistEntity dist = distService.getInfo(id);

        return R.ok().put(dist);
    }

    /**
     * 业务数据字典保存
     */
    @SysLog("业务数据字典保存")
    @ApiOperation("业务数据字典保存")
    @PostMapping("/save")
    @RequiresPermissions("base:Dist:save")
    public R save(@RequestBody DistEntity dist){

		distService.saveInfo(dist);

        return R.ok();
    }

    /**
     * 业务数据字典修改
     */
    @SysLog("业务数据字典修改")
    @ApiOperation("业务数据字典修改")
    @PostMapping("/update")
    @RequiresPermissions("base:dist:update")
    public R update(@RequestBody DistEntity dist){

		distService.updateInfo(dist);

        return R.ok();
    }

    /**
     * 业务数据字典删除
     */
    @SysLog("业务数据字典删除")
    @ApiOperation("业务数据字典删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("base:dist:delete")
    public R delete(@PathVariable("id") Long id){

		distService.deleteInfo(id);

        return R.ok();
    }


    /**
     * 业务数据字典审核
     */
    @SysLog("业务数据字典审核")
    @ApiOperation("业务数据字典审核")
    @GetMapping("/check/{id}")
    @RequiresPermissions("base:dist:check")
    public R check(@PathVariable("id") Long id){

        distService.checkInfo(id);

        return R.ok();
    }


    /**
     * 业务数据字典导出
     */
    @SysLog("业务数据字典导出")
    @ApiOperation("业务数据字典导出")
    @GetMapping("/export")
    @RequiresPermissions("base:dist:export")
    public void export(@RequestParam Map<String, Object> params){

        List<DistExportVO> list = distService.exportList(params);

        exportExcel(list,"业务数据字典","业务数据字典",DistExportVO.class,"业务数据字典.xls");
    }


    /**
     * 分类树状
     * @param
     * @throws Exception
     */
    @SysLog("分类树状")
    @RequiresPermissions("base:dist:list")
    @PostMapping("/tree")
    public R tree(@RequestParam Map<String, Object> params)  {
        return R.ok().put( distService.queryTreeAll(params));
    }


}
